<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class FNews extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('car_model');
		$this->load->model('news_model');
		$this->load->library('pagination');
		
	}

	function index()
	{
		$page["_contents"] = "frontend/news/v_news";

		$config['base_url'] = base_url().'FNews/index';
		$config['total_rows'] = $this->news_model->publishCount();
		$config['per_page'] = 10;
		$config['uri_segment'] = 3;
		$config['num_links'] = 3;
		$config['full_tag_open'] = '<ul class="pagination">';
		$config['full_tag_close'] = '</ul>';
		$config['next_link'] = '&raquo;';
		$config['next_tag_open'] = '<li>';
		$config['next_tag_close'] = '</li>';
		$config['prev_link'] = '&laquo;';
		$config['prev_tag_open'] = '<li>';
		$config['prev_tag_close'] = '</li>';
		$config['cur_tag_open'] = '<li><a href="#">';
		$config['cur_tag_close'] = '</a></li>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		
		$this->pagination->initialize($config);

		$paging = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["query"] = $this->news_model->getAllPaging($config["per_page"], $paging);
		$data["link"] = $this->pagination->create_links();
		$data["count"] = $this->news_model->publishCount();

		$this->template->load("frontend/template/main_template",$page,$data);
	}

	function readmore()
	{
		$id = $this->uri->segment(3);
		
		$row = $this->news_model->get_by_id($id)->row();
		
		$arr = array(array('id' => $id, 
						   'title' => $row->title, 
						   'content' => $row->content, 
						   'image' => $row->image
						   )
					);
		echo json_encode($arr );
	}

}

/* End of file FNews.php */
/* Location: ./application/controllers/FNews.php */